const treeData = require("./treeData");
const { clone } = require("../cloneDeep");

/**
 *
 * @param {any[]} treeData
 */
function getDepthLastLevelNodes(treeData, result = []) {
  treeData.forEach((item) => {
    if (item.children && item.children.length) {
      getDepthLastLevelNodes(item.children, result);
    } else {
      result.push(item);
    }
  });
  return result;
}

const lastLevelNodes = getDepthLastLevelNodes(treeData);
console.log(lastLevelNodes, "lastLevelNodes");
